
#include <BRender>
#include <BMaterial>
#include <BState>
#include <BCone>
#include "member_BCone.h"

using namespace BWE;

#define member					(*(member_BCone*)_ptr)
#define member_allocate()		_ptr = new member_BCone(this)
#define member_release()		delete (member_BCone*)_ptr

BCone::BCone()
{
	member_allocate();
}
BCone::BCone(float radius, float height, int sides, int segments, int bottomSegments)
{
	member_allocate();
	member.radius = radius;
	member.height = height;
	member.sides = sides;
	member.segments = segments;
	member.bottomSegments = bottomSegments;
	member.prepare();
	this->dirty();
}
BCone::~BCone()
{
	member_release();
}

void BCone::setRadius(float radius)
{
	if (member.radius != radius)
	{
		member.radius = radius;
		this->dirty();
	}
}
float BCone::radius() const
{
	return member.radius;
}

void BCone::setHeight(float height)
{
	if (member.height != height)
	{
		member.height = height;
		this->dirty();
	}
}
float BCone::height() const
{
	return member.height;
}

void BCone::setSides(int sides)
{
	if (member.sides != sides)
	{
		member.sides = sides;
		member.prepare();
		this->dirty();
	}
}
int BCone::sides() const
{
	return member.sides;
}

void BCone::setSegments(int segments)
{
	if (member.segments != segments)
	{
		member.segments = segments;
		this->dirty();
	}
}
int BCone::segments() const
{
	return member.segments;
}

void BCone::setBottomSegments(int bottomSegments)
{
	if (member.bottomSegments != bottomSegments)
	{
		member.bottomSegments = bottomSegments;
		this->dirty();
	}
}
int BCone::bottomSegments() const
{
	return member.bottomSegments;
}

void BCone::refresh()
{
	BSpace space;
	space.min().set(-member.radius, -member.radius, 0);
	space.max().set(member.radius, member.radius, member.height);
	this->setSpace(space);
	member.rebuild();
}
void BCone::render(BRender& render)
{
	BGeometry::render(render);

	//if (this->vertices())
	//{
	//	render.setDepthTest(false);
	//	render.setColor(200, 0, 0);
	//	render.setPointSize(5);
	//	render.drawPoints(*this->vertices());
	//}
}
